namespace CE.Parsers.CS
{
    using System.Windows.Forms;

	public class CSParser
	{
		#region Methods

		public static void ParseToTree(string fileName, TreeNodeCollection nodes)
		{
			CE.Parsers.CS.Scanner scanner = new CE.Parsers.CS.Scanner(fileName);
			CE.Parsers.CS.Parser parser = new CE.Parsers.CS.Parser(scanner);
			parser.Parse();

			// Using...
			TreeNode nUsing = new TreeNode("Usings");
			nUsing.ImageIndex = 11;
			nUsing.SelectedImageIndex = 11;
			foreach (TokenMatch tm in parser.CodeInfo.Usings) {
				TreeNode n = new TreeNode(tm.Value);
				n.Tag = tm.Position;
				nUsing.Nodes.Add(n);
				n.ImageIndex = 11;
				n.SelectedImageIndex = 11;
			}
			if (nUsing.Nodes.Count > 0) {
				nodes.Add(nUsing);
			}

			// Class...
			TreeNode nClass = new TreeNode("Class");
			foreach (TokenMatch tm in parser.CodeInfo.Classes) {
				TreeNode n = new TreeNode(tm.Value);
				n.Tag = tm.Position;
				nClass.Nodes.Add(n);
			}
			if (nClass.Nodes.Count > 0) {
				nodes.Add(nClass);
				nClass.Expand();
			}

			// Constructors...
			TreeNode nConstruct = new TreeNode("Constructors");
			nConstruct.ImageIndex = 10;
			nConstruct.SelectedImageIndex = 10;
			foreach (TokenMatch tm in parser.CodeInfo.Constructors) {
				TreeNode n = new TreeNode(tm.Value);
				n.Tag = tm.Position;
				nConstruct.Nodes.Add(n);
				n.ImageIndex = 10;
				n.SelectedImageIndex = 10;
			}
			if (nConstruct.Nodes.Count > 0) {
				nodes.Add(nConstruct);
				nConstruct.Expand();
			}

			/*// Namespace...
			   TreeNode nName = new TreeNode("Namespaces");
			   nName.ImageIndex=11;
			   nName.SelectedImageIndex=11;
			   int i=0;
			   foreach (string tm in parser.CodeInfo.NameSpaces)
			   {

			    TreeNode n = new TreeNode(tm.ToString());
			    n.Tag = i++;
			    nName.Nodes.Add(n);
			    n.ImageIndex = 11;
			    n.SelectedImageIndex = 11;
			   }
			   if (nName.Nodes.Count > 0)
			   {
			    nodes.Add(nName);
			    nName.Expand();
			    //this.m_Control.AddNode(nName);
			   }*/

			// Fields...
			TreeNode nField = new TreeNode("Fields");
			nField.ImageIndex = 8;
			nField.SelectedImageIndex = 8;
			foreach (TokenMatch tm in parser.CodeInfo.Fields) {
				TreeNode n = new TreeNode(tm.Value);
				n.Tag = tm.Position;
				nField.Nodes.Add(n);
				n.ImageIndex = 8;
				n.SelectedImageIndex = 8;
			}
			if (nField.Nodes.Count > 0) {
				nodes.Add(nField);
				nField.Expand();
			}

			// Methods...
			TreeNode nMethod = new TreeNode("Methods");
			nMethod.ImageIndex = 10;
			nMethod.SelectedImageIndex = 10;
			//nMethod.
			foreach (TokenMatch tm in parser.CodeInfo.Methods) {
				TreeNode n = new TreeNode(tm.Value);
				n.Tag = tm.Position;
				nMethod.Nodes.Add(n);
				n.SelectedImageIndex = 10;
				n.ImageIndex = 10;
			}
			if (nMethod.Nodes.Count > 0) {
				nodes.Add(nMethod);
				nMethod.Expand();
			}

			// Properties...
			TreeNode nProps = new TreeNode("Properties");
			nProps.ImageIndex = 12;
			nProps.SelectedImageIndex = 12;
			foreach (TokenMatch tm in parser.CodeInfo.Properties) {
				TreeNode n = new TreeNode(tm.Value);
				n.Tag = tm.Position;
				nProps.Nodes.Add(n);
				n.ImageIndex = 12;
			}
			if (nProps.Nodes.Count > 0) {
				nodes.Add(nProps);
				nProps.Expand();
			}
		}

		#endregion Methods
	}
}